package ace.module.oss.core.impl.manager.impl;

import ace.cmp.core.constants.CoreConstant;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.module.oss.api.model.dto.OssApplicationDto;
import ace.module.oss.core.impl.dao.entity.OssApplication;
import ace.module.oss.core.impl.dao.repository.OssApplicationRepository;
import ace.module.oss.core.impl.manager.OssApplicationManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 对象存储应用 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class OssApplicationManagerImpl
    extends AbstractSpringDtoManager<OssApplication, Long,  OssApplicationDto>
    implements OssApplicationManager {

  private final OssApplicationRepository ossApplicationRepository;
  private final MessageSourceAssertService assertService;

  @Override
  public OssApplication getAndCheckById(Long id) {
    OssApplication ossApplication = this.ossApplicationRepository.getById(id);
    assertService.isNull(
        ossApplication, OssApplication.class.getName() + ".error-is-null", "应用不存在");
    assertService.isFalse(
        ossApplication.getDeleteFlag().equals(CoreConstant.DELETE_FLAG_NOT),
        "account.password.error-is-null",
        "应用不存在");
    return ossApplication;
  }
}
